<template>
  <div v-if="visible">
    <el-dialog :visible.sync="visible"
               :title="title"
               :modal="false"
               class="user-dialog add-or-updata"
               width="35%"
               :before-close="closeDialog"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form :model="dataForm"
               class="label-left-form"
               v-loading="dataListLoading"
               :element-loading-text="$t('loading')"
               ref="dataForm"
               label-position="top"
               @keyup.enter.native="dataFormSubmitHandle()"
               label-width="120px">
        <el-form-item prop="textarea"
                      :rules="stringRule(true,0,80)">
          <el-input v-model.trim="dataForm.textarea"
                    type="textarea"
                    maxlength="80"
                    :rows="5"
                    show-word-limit
                    placeholder="请输入信息"></el-input>
        </el-form-item>
      </el-form>
      <template slot="footer">
        <el-button @click="closeDialog()">{{ $t('cancel')}}</el-button>
        <el-button type="primary"
                   :loading="dataListLoading"
                   @click="dataFormSubmitHandle()">{{ $t('confirm')}}</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import minFormValidate from '@/mixins/form-validate'
import debounce from 'lodash/debounce'
export default {
  mixins: [mixinViewModule, minFormValidate],
  props: {
    isRquired: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '不通过原因'
    }
  },
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '', // 数据列表接口，API地址
        getDataListIsPage: true, // 数据列表接口，是否需要分页？
        addOrUpdateURL: '', // 添加或修改接口，API地址
        getDataInfoURL: '', // 数据详情，API地址
        deleteURL: '', // 删除接口，API地址
        deleteIsBatch: true, // 删除接口，是否需要批量？
        exportURL: '' // 导出接口，API地址
      },
      info: {},
      visible: false,
      dataForm: {
        textarea: ''
      }
    }
  },
  methods: {
    closeDialog () {
      this.visible = false
      this.$refs.dataForm.resetFields()
    },
    init (data) {
      data = data || {}
      this.info = Object.assign({}, {}, data)
      this.visible = true
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.$emit('callBack', {
            text: this.dataForm.textarea,
            ...this.info
          })
          this.closeDialog()
        }
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>

<style lang="scss" scoped>
</style>
